package com.guanglan.serviceImpl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.guanglan.dao.SysRoleMapper;
import com.guanglan.dao.SysRolePermissionMapper;
import com.guanglan.dao.SysUserRoleMapper;
import com.guanglan.domain.SysRole;
import com.guanglan.service.SysRoleService;

@Service
public class SysRoleServiceImpl implements SysRoleService {
	
	Logger log = LoggerFactory.getLogger(SysRoleServiceImpl.class);
	
	@Autowired
	private SysRoleMapper roleMapper;
	@Autowired
	private SysRolePermissionMapper rolePermissionMapper;
	@Autowired
	private SysUserRoleMapper userRoleMapper;

	
	@Transactional
	public int deleteByPrimaryKey(Long id) {
		int count = roleMapper.deleteByPrimaryKey(id);
		log.info("del用户信息{}",count > 0 ? "成功":"失败");
		int urCount = userRoleMapper.deleteByRoleId(id);
		log.info("del用户角色信息{}",urCount > 0 ? "成功":"失败");
		int rpCount = rolePermissionMapper.deleteByPid(id);
		log.info("del角色权限信息{}",rpCount > 0 ? "成功":"失败");
		
		return count;
	}

	public int insert(SysRole record) {
		// TODO Auto-generated method stub
		return 0;
	}

	public int insertSelective(SysRole record) {
		// TODO Auto-generated method stub
		return 0;
	}

	public SysRole selectByPrimaryKey(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	public int updateByPrimaryKeySelective(SysRole record) {
		// TODO Auto-generated method stub
		return 0;
	}

	public int updateByPrimaryKey(SysRole record) {
		// TODO Auto-generated method stub
		return 0;
	}

	public List<SysRole> selectByRoleId(List<Long> list) {
		log.debug("查找到的roleids-长度=【{}】",list.size());
		return roleMapper.selectByRoleId(list);
	}

	@Override
	public List<SysRole> getRoles(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return roleMapper.getRoles(params);
	}

	@Override
	public Integer getRolesCount(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return roleMapper.getRolesCount(params);
	}

}
